package com.atguigui.leetcode1;

/**
 * 2383.赢得比赛需要的最少训练时长
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/3/13 8:50
 */
public class P2383MinimumHoursOfTrainingToWinACompetition {
    public static void main(String[] args) {
        Solution solution = new P2383MinimumHoursOfTrainingToWinACompetition().new Solution();
        // TO TEST
    }

    class Solution {
        public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
            //需要的总能量
            int sum = 0;
            for (int e : energy) {
                sum += e;
            }
            //需要的能力训练时间
            int trainingHours = initialEnergy > sum ? 0 : sum + 1 - initialEnergy;
            for (int e : experience) {
                if (initialExperience <= e) {
                    //加上训练小时
                    trainingHours += 1 + (e - initialExperience);
                    //总经验累计
                    initialExperience = 2 * e + 1;
                } else {
                    initialExperience += e;
                }
            }

            return trainingHours;
        }
    }
}
